package com.cts.tmall.dal.provider;

import org.apache.commons.lang3.StringUtils;

import java.util.Date;

public class TmallTimingSaleProvider {
    public static String queryTimingSaleSql(String prdNo, String prdName, Date saleStartTime, Date saleEndTime, Long createUserId) {
        StringBuffer sb = new StringBuffer();
        sb.append("select a.* from tmall_timing_sale a left join tmall_prd b on a.prd_no = b.prd_no where a.create_user_id = #{createUserId,jdbcType=BIGINT}");
        if (StringUtils.isNotBlank(prdNo)) {
            sb.append(" and b.prdNo = #{prdNo,jdbcType=VARCHAR}");
        }
        if (StringUtils.isNotBlank(prdName)) {
            sb.append(" and b.prdName = #{prdName,jdbcType=VARCHAR");
        }
        if (saleStartTime != null) {
            sb.append(" and a.saleTime >= #{saleStartTime,jdbcType=Timestamp}");
        }
        if (saleEndTime != null) {
            sb.append(" and a.saleTime <= #{saleEndTime,jdbcType=Timestamp}");
        }
        return sb.toString();
    }
}
